package org.ndky.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RefreshScope
public class HelloController {

    //from serviceName-env.yml
    //ex. service-config-dev.yml
    //priority level: High
    //NOTICE: it will ignore the value of same key in subsequent files if it already read at this level
    @Value("${lesson05.name}")
    private String nameEnv;

    //from serviceName.yml
    //ex. service-config.yml
    //priority level: Medium
    @Value("${lesson05.nameNoEnv}")
    private String nameNoEnv;

    //from sharedConfig-env.yml
    //ex. application-dev.yml
    //priority level: Low
    @Value("${ribbon.ReadTimeout}")
    private String nameSharedConfEnv;

    //from sharedConfig.yml---Invalid
    //ex. application.yml
//    @Value("${lesson05.sharedConfigNoEnv}")
//    private String nameSharedConfNoEnv;

    @GetMapping("config/hello")
    public String hello(){
        return "[CONFIG] nameEnv:" + nameEnv
                + ", nameNoEnv: " + nameNoEnv
                + ", nameSharedConfEnv: " + nameSharedConfEnv;
    }


}
